{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "from common.configs.tools import label_map, save_json, load_json\n",
    "import pandas as pd"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [
    "res = pd.read_csv(r'./result_5.csv')\n",
    "res.head()"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "bert_test_results = res.label.apply(lambda e: label_map[e]).tolist()"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "bert_valid = load_json(r'./result_val_bert.json')\n",
    "index_json = load_json(r'./index.json')\n",
    "bert_train = load_json(r'./result_train_bert.json')\n"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "k_bert_out = {'train': {}, 'valid': {}}\n",
    "for k, v in index_json.items():\n",
    "    res_json = bert_valid[k]\n",
    "    train_res_json = bert_train[k]\n",
    "    valid_index = pd.Series(v['valid_index']).apply(lambda e: label_map[res_json[str(e)]])\n",
    "    train_index = pd.Series(v['train_index']).apply(lambda e: label_map[train_res_json[str(e)]])\n",
    "\n",
    "    k_bert_out['valid'][k] = valid_index.to_list()\n",
    "    k_bert_out['train'][k] = train_index.to_list()\n"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "out_json = {'test_res': bert_test_results, 'valid_train': k_bert_out, }"
   ],
   "outputs": [
    {
     "output_type": "error",
     "ename": "NameError",
     "evalue": "name 'bert_test_results' is not defined",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-810538a9e313>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mout_json\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;34m'test_res'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbert_test_results\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'valid_train'\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mk_bert_out\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m: name 'bert_test_results' is not defined"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "source": [
    "save_json(r'bert_res.json', out_json)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "bert_res.json saved.\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "source": [
    "out_json = load_json(r'bert_res.json')"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "out_json['train_valid'] = k_bert_out"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "source": [
    "len(k_bert_out['train'][\"2\"])"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "11207"
      ]
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [],
   "outputs": [],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.6.12",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.6.12 64-bit ('py36': conda)"
  },
  "interpreter": {
   "hash": "2e2ff3a457722a20f87dbf10c05994872f65588779806bce29ecd514429d1c22"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}